/*
 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 *
 * SPDX-License-Identifier: MIT
 */
/*
 * @Hardwares: M5Core + Unit PbHub
 * @Platform Version: Arduino M5Stack Board Manager v2.1.3
 * @Dependent Library:
 * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
 */

#include <M5Stack.h>
#include <Wire.h>

#include "porthub.h"

#define X_OFFSET 10
#define Y_OFFSET 18

PortHub porthub;
uint8_t HUB_ADDR[6] = {HUB1_ADDR, HUB2_ADDR, HUB3_ADDR, HUB4_ADDR, HUB5_ADDR, HUB6_ADDR};

void setup()
{
    M5.begin(true, false, true);
    M5.Power.begin();
    porthub.begin();
    M5.Lcd.clear(BLACK);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.setTextSize(4);
}

void loop()
{
    M5.Lcd.clear(BLACK);
    for (int i = 0; i < 6; i++) {
        M5.Lcd.setCursor(8 * X_OFFSET, (i * 2) * Y_OFFSET);
        M5.Lcd.printf("%d:%d", i + 1, porthub.hub_a_read_value(HUB_ADDR[i]));
    }

    for (int i = 0; i < 6; i++) {
        porthub.hub_wire_setBrightness(HUB_ADDR[i], 1);
        porthub.hub_wire_fill_color(HUB_ADDR[i], 0, 15, 250, 250, 250);
    }
    delay(1000);
}